$(function ()
{
    findType();
})

function findType()
{
    let data = publivAjax('/back/newTypeList', {}, 'get');

    let list = data.list;
    let html = '<option value="0" selected>无</option>';

    if (list != null)
    {
        sessionStorage.setItem("defaultSelectId", list[0].id);
        for (let i = 0; i < list.length; i++)
        {
            html += '<option value="' + list[i].id + '">' + list[i].typeName + '</option>';
        }
    }

    $('#newType').html(html);
}

function selectType()
{
    let newType = $('#newType').val();
    let type = $('#type').val();
    if (newType == 0 && type != "设施介绍")
    {
        $('#type').val("设施介绍");
    }
    else if (newType!=0&&type != "酒店新闻")
    {
        $('#type').val("酒店新闻");
    }
}

function judge()
{
    let type = $('#type').val();
    let newType = $('#newType').val();
    let defaultSelectId = sessionStorage.getItem("defaultSelectId");
    if (type == "设施介绍" && newType != 0)
    {
        $('#newType').val(0);
    }
    else if (type == "酒店新闻" && newType == 0)
    {
        $('#newType').val(defaultSelectId);
    }
}

function save()
{
    let msg = {};
    msg.title = $.trim($("#title").val());
    msg.from = $.trim($("#from").val());
    msg.author = $.trim($("#author").val());
    msg.type = $("#type").val();
    msg.isShow = $("input[name='isShow']:checked").val();
    msg.recommend = $("input[name='recommend']:checked").val();
    msg.content = $("#content").val();
    msg.introduction = $("#introduction").val();
    msg.newType = $("#newType").val();

    let data = publivAjax('/back/new/add', msg, 'post');

    if (data.count == 1)
    {
        $('#b-right').load('/back/new/newList.html');
    }
    else
    {
        alert("新增失败！");
    }
}